var PhotoLocalName = "";
var imgType = 1;
jQuery(function ($)
{
    initdata(pagenum);
	 Calendar.setup(
    {
        inputField : "startime_str", trigger : "startime_str", dateFormat : "%Y-%m-%d", min :new Date(),
        onSelect : function () 
        {  
            this.hide();
            computDate();
        }
    });
    swfobject.embedSWF("/ASUploader.swf", "uploadstar", "60", "22", "10.0.0", "expressInstall.swf", 

    {
        url : "http://room.img.17guagua.com/uploadImg.jsp", txt : "\u4E0A\u4F20\u56FE\u7247", p : "1", align : "left", callback : "setType(2)",maxcallback:"imgSizeAlert"
    },
    {
        wmode : "transparent"
    },
    {});
    swfobject.embedSWF("/ASUploader.swf", "uploadroom", "60", "22", "10.0.0", "expressInstall.swf", 

    {
        url : "http://room.img.17guagua.com/uploadImg.jsp", txt : "\u4E0A\u4F20", p : "1", align : "right", callback : "setType(1)",maxcallback:"imgSizeAlert"
    },
    {
        wmode : "transparent"
    },
    {});
    swfobject.embedSWF("/ASUploader.swf", "uploadactive", "60", "22", "10.0.0", "expressInstall.swf", 

    {
        url : "http://room.img.17guagua.com/uploadImg.jsp", txt : "\u6DFB\u52A0\u6D77\u62A5", p : "3", callback : "setType(3)",maxcallback:"imgSizeAlert"
    },
    {
        wmode : "transparent"
    },
    {});
});
function imgSizeAlert(){
   alert("\u6587\u4EF6\u6700\u5927\u4E3A500k,\u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6");
   return;
}
function setType(type)
{
    imgType = type;
}
//  \u521D\u59CB\u5316,as \u8C03\u7528\u521D\u59CB\u5316\u3002
function fileInit() { } //   0\u5931\u8D25 \u4E0D\u7B49\u4E8E0 \u5219\u56FE\u7247\u8DEF\u5F84
function cHandler(result, name)
{ 
    //var ret = result.replace(/(^\s*)|(\s*$)/g, "");
   if (eval("(" + result + ")").result == 0){
        
        PhotoLocalName = name;
        if (imgType != 3) {
            showCropDiv(eval("(" + result + ")").value, imgType);
        }
        else {
            showCropActiveDiv(eval("(" + result + ")").value);
        }
    }else if (eval("(" + result + ")").result == -2){
        alert("\u56FE\u7247\u5C3A\u5BF8\u4E0D\u6B63\u786E\uFF0C\u56FE\u7247\u8981\u6C42\u4ECB\u4E8E36*36 \u548C1024*1024\u4E4B\u95F4");
        return false;
    }else if (eval("(" + result + ")").result == -3){
        alert("\u56FE\u7247\u5C3A\u5BF8\u4E0D\u6B63\u786E\uFF0C\u56FE\u7247\u8981\u6C42\u4ECB\u4E8E511*262 \u548C1024*1024\u4E4B\u95F4");
        return false;
    }else{
        alert("\u4E0A\u4F20\u56FE\u7247\u5931\u8D25");
        return false;
    }
}
// \u8FDB\u5EA6\uFF0Ci \u8FDB\u5EA6\u503C\uFF0C\u57281-100\u76F4\u63A5
function progressHandler(i)
{
    $("#uploadprocess").show();
    $("#uploadBar").css("width", i * 2 + "px");
    if (i == 100) {
        $("#uploadprocess").hide();
    }
}
// \u8BBE\u7F6E\u53C2\u6570
function setKey(p)
{
    thisMovie("uploadstar").setKey(p);
}
function thisMovie(movieName) 
{
    //return swfobject.getObjectById(movieName);
    if (navigator.appName.indexOf("Microsoft") != - 1) {
        return window[movieName] 
    }
    else {
        return document[movieName] ;
    }
}
function computDate()
{
    $("#endtime").html("");
	if ( $("#startime_hour").val() !="" && Number($("#startime_hour").val())>=24){
		    $("#startime_hour").val("00");
		    alert("\u5F55\u5165\u65F6\u95F4\u4E0D\u6B63\u786E\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165");
         }	
	if ($("#startime_min").val() !="" && Number($("#startime_min").val())>=60){
			$("#startime_min").val("00");
		    alert("\u5F55\u5165\u65F6\u95F4\u4E0D\u6B63\u786E\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165");
         }
    if ($("#startime_str").val() != "\u5F00\u59CB\u65E5\u671F" && $("#startime_hour").val() !="" && $("#startime_min").val() !=""&&$("#active_time").val() >0)
    {	
        var startime = new Date(($("#startime_str").val() + " "+$("#startime_hour").val()+":"+$("#startime_min").val()+":00").replace(/-/g,  "/"));
        startime.setMinutes(startime.getMinutes() + Number($("#active_time").val()), startime.getSeconds(), 0);
		$("#endtime").html(startime.getFullYear()+"-"+("" + (startime.getMonth() + 101)).substr(1)+"-"+ ("" + (startime.getDate() + 100)).substr(1)+" "+("" + (startime.getHours() + 100)).substr(1)+":"+ ("" + (startime.getMinutes() + 100)).substr(1));
    }
}
function showCropDiv(imgUrl, picType)
{
    $('#target').attr("src", imgUrl);
    $('#preview').attr("src", imgUrl);
    $('#cropImg').show();
    initCrop();
    $('#subCrop').unbind();
    $('#subCrop').click(function ()
    {
        subCrop(picType);
    });
}
function showCropActiveDiv(imgUrl)
{
    $('#targetActive').attr("src", imgUrl);
    AutoResizeImage(217, 100, $('#targetActive'));
    $('#cropActiveImg').show();
    //initCropActive(ratio);
}
function subCrop(picType)
{
    var request = $.ajax(
    {
        url : "/room!cropImg.jspa", type : "post", data : 
        {
            x1 : $('#x1').val(), y1 : $('#y1').val(), x2 : $('#x2').val(), y2 : $('#y2').val(), mw : $('#hideDivForPre').width(), 
            mh : $('#hideDivForPre').height(), imgsrc : $('#target').attr("src")
        },
        dataType : "text",
        complete : function (data, textStatus)
        {   
           
            if(textStatus.indexOf("error") > 0 ){
               return;
            }
         try{
            if (eval("(" + data.responseText + ")").result == 0)
            {
                if (picType == 1)
                {
                    $('#roomavatar').attr("src", eval("(" + data.responseText + ")").value + "?c=" + (new Date().valueOf()));
                }
                else
                {
                    $('#avatar').attr("src", eval("(" + data.responseText + ")").value + "?c=" + (new Date().valueOf()));
                }
                jcrop_api.destroy();
                $('#cropImg').hide();
            }
            else {
                alert("\u88C1\u526A\u56FE\u7247\u5931\u8D25,\u7528\u6237\u672A\u767B\u5F55");
                return false;
            }
          }catch(err)
				{
				   return;
				}
        }
    });
}
function subCropActive()
{

    var request = $.ajax(
    {
        url : "/room!cropImg.jspa?mw=216&mw=511&mh=111&mh=262", type : "GET", data : 
        {
            x1 : $('#x1').val(), y1 : $('#y1').val(), x2 : $('#x2').val(), y2 : $('#y2').val(),
            imgsrc : $('#targetActive').attr("src")
        },
        dataType : "text",
        complete : function (data, textStatus)
        {
            if(textStatus.indexOf("error") > 0 ){
               return;
            }
          try{
            if (eval("(" + data.responseText + ")").result == 0)
            {
                $('#active_avatar').attr("src", eval("(" + data.responseText + ")").value[0] + "?c=" + (new Date().valueOf()));
                jcrop_api.destroy();
                $('#cropActiveImg').hide();
				$('#uploadactive').hide();
				$("#ywc_pho_name").html(PhotoLocalName);
				$("#ywc_del_h").attr("href", "javascript:delImg($('#active_avatar').attr('src'));delActivePho(0);");
				$("#ywc").show();
            }
            else {
                alert("\u88C1\u526A\u56FE\u7247\u5931\u8D25,\u7528\u6237\u672A\u767B\u5F55");
                return false;
            }
          }catch(err)
				{
				   return;
				}
        }
    });
}
function subStar()
{
    if ($('#subject').val() == "") {
        alert("\u8BF7\u586B\u5199\u533A\u57DF\u540D\u79F0\uFF01");
        return false;
    }
    if ($('#nickname').val() == "") {
        alert("\u8BF7\u586B\u5199\u6635\u79F0\uFF01");
        return false;
    }
    if ($('#user_id').val() == "") {
        alert("\u8BF7\u586B\u5199ID\uFF01");
        return false;
    }
    if ($('#url').val() == "") {
        alert("\u8BF7\u586B\u5199\u8D85\u94FE\u63A5\u4EE5http://\u5F00\u5934\uFF01");
        return false;
    }
    if(!isURL($('#url').val())){
       alert("\u8D85\u94FE\u63A5\u683C\u5F0F\u4E0D\u6B63\u786E\uFF01");
       return false;
    }
    if ($('#introduce').val().length > 50) {
        alert("\u4FE1\u606F\u8981\u6C42\u572850\u5B57\u4EE5\u5185");
        return false;
    }
     if ($('#avatar').attr("src").indexOf("?")<0) {
        alert("\u8BF7\u4E0A\u4F20\u5934\u50CF\uFF01");
        return false;
    }
    var request = $.ajax(
    {
        url : "/room!addStar.jspa", type : "post", data : 
        {
            "star.subject" : $('#subject').val(), "star.nickname" : $('#nickname').val(), "star.user_id" : $('#user_id').val(), 
            "star.url" : $('#url').val(), "star.introduce" : $('#introduce').val(), "star.room_id" : $('#room_id').val(), 
            "photo.photo_path" : $('#avatar').attr("src"), "photo.photo_type_id" : 2, "photo.size_id" : 1, 
            "photo.photo_name" : PhotoLocalName
        },
        dataType : "json",
        complete : function (data, textStatus)
        {
            if (eval("(" + data.responseText + ")").result == 0)
            {
                $('#nickname').val("");
                $('#user_id').val("");
                $('#url').val("http://");
                $('#introduce').val("");
                $('#avatar').attr("src", "/images/img/but_3.jpg");
                alert("\u6210\u529F\u6DFB\u52A0\u660E\u661F");
            }
            else {
                alert("\u6DFB\u52A0\u660E\u661F\u5931\u8D25");
            }
        }
    });
}
function subDelStar(starid, photoid)
{
    var request = $.ajax(
    {
        url : "/room!delStar.jspa", type : "post", data : {
            "star.id" : starid, "star.room_id" : $('#room_id').val(), "photo.id" : photoid
        },
        dataType : "json",
        complete : function (data, textStatus)
        {
            if (eval("(" + data.responseText + ")").result == 0) {
                delImg($("#starImg" + starid).attr("src"));
                $("#star" + starid).remove();
            }
        }
    });
}
function subActive()
{
    if ($('#active_subject').val() == "\u6D3B\u52A8\u6807\u9898\u6700\u591A\u8F93\u516515\u4E2A\u6C49\u5B57") {
        alert("\u6D3B\u52A8\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A");
        return;
    }
    if ($('#startime_str').val() == "\u5F00\u59CB\u65E5\u671F" ||$('#startime_hour').val()=="" ||$('#startime_hour').val()=="") {
        alert("\u6D3B\u52A8\u5F00\u59CB\u65F6\u95F4\u4E0D\u80FD\u4E3A\u7A7A");
        return;
    }
    if ($("#active_time").val() ==0) {
        alert("\u8BF7\u9009\u62E9\u6D3B\u52A8\u7ED3\u675F\u65F6\u957F");
        return;
    }
	if ($('#active_content').val()=="\u6D3B\u52A8\u4ECB\u7ECD\u6700\u591A50\u4E2A\u6C49\u5B57") {
        $('#active_content').val("");
    }else{
		if ($('#active_content').val().length > 100) {
			alert("\u6D3B\u52A8\u7B80\u4ECB\u8981\u6C42\u5728100\u5B57\u4EE5\u5185");
			return;
		}
	}
	var center_flag=0;
	if($("#center_flag").attr("checked")=="checked"){
	    center_flag=1;
	}
    var request = $.ajax(
    {
        url : "/room!addActive.jspa", type : "post", data : 
        {
            "active.active_subject" : $('#active_subject').val(), "active.startime_str" : $('#startime_str').val()+" "+$('#startime_hour').val()+":"+$('#startime_min').val(), 
            "active.endtime_str" : $('#endtime').html(), "active.active_content" : $('#active_content').val(), 
			"active.tag_catalog_id" : $('#tag_category').val(),"active.tag_id" : $('#tag_id').val(),"active.center_flag" : center_flag,
            "active.room_id" : $('#room_id').val(), "photo.photo_path" : $('#active_avatar').attr("src"), 
            "photo.photo_type_id" : 3, "photo.size_id" : 3, "photo.photo_name" : PhotoLocalName
        },
        dataType : "json",
        complete : function (data, textStatus)
        {
            if (data.responseText!="" && eval("(" + data.responseText + ")").result == 0)
            {
                $('#active_subject').val("");
                $('#startime_str').val("");
				$('#startime_hour').val("00");
				$('#startime_min').val("00");
                $('#endtime').html("");
                $('#active_content').val("");
                $("#active_time").val("0");
                $('#active_avatar').attr("src", "/images/Head.jpg");
				$("#ywc").hide();
				$('#uploadactive').show();
				$("#center_flag").attr("checked",false);
				$('#tag_category').val("0");
				$("#tag_id option").remove();
				$("#tag_id").append("<option value='0'>\u8BF7\u9009\u62E9</option>");
				$('#tag_id').val("0");
				$("#tag_category").attr("disabled","disabled");
			    $("#tag_id").attr("disabled","disabled");
                alert("\u6210\u529F\u6DFB\u52A0\u6D3B\u52A8");
            }
            else {
                alert("\u6DFB\u52A0\u6D3B\u52A8\u5931\u8D25");
            }
        }
    });
}
function editActive(activeId)
{
  $('#active_subject').val($('#preASubject'+activeId).html());
  $('#startime_str').val($("#ac_start_time_"+activeId).val().substr(0,10));
  $('#startime_hour').val($("#ac_start_time_"+activeId).val().substr(11,2));
  $('#startime_min').val($("#ac_start_time_"+activeId).val().substr(14,2));
  $('#active_time').val((new Date($("#ac_end_time_"+activeId).val().replace(/-/g,  "/"))-new Date($("#ac_start_time_"+activeId).val().replace(/-/g,  "/")))/60000);
  $('#active_content').val($('#preAContent'+activeId).html());
  computDate();
  $("#ywc_pho_name").html($("#ac_photo_name_"+activeId).val());
  if (Number($("#ac_centerflag_"+activeId).val())==1){
     $("#center_flag").attr("checked",true);
  }
  $("#center_flag").attr("disabled","disabled");
  $("#startime_str").attr("disabled","disabled");
  $('#startime_hour').attr("disabled","disabled");
  $('#startime_min').attr("disabled","disabled");
  $("#active_time").attr("disabled","disabled");
  if($("#preactiveAvatar" + activeId).attr("src")!=null&&$("#preactiveAvatar" + activeId).attr("src")!=""){
    $('#active_avatar').attr("src", $("#preactiveAvatar" + activeId).attr("src"));
    $('#uploadactive').hide();
	$("#ywc").show();
  }
  $("#activeSub").attr("href", "javascript:subEditActive("+activeId+");");
  $("#ywc_del_h").attr("href", "javascript:delActivePho("+activeId+");");
  
}
function subEditActive(activeId)
{
    if ($('#active_subject').val() == "") {
        alert("\u6D3B\u52A8\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A");
        return;
    }
    var request = $.ajax(
    {
        url : "/room!editActive.jspa", type : "post", data : 
        {
            "active.active_subject" : $('#active_subject').val(),
            "active.active_content" : $('#active_content').val(), "active.room_id" : $('#room_id').val(),
            "active.id" : activeId,"active.image" :$('#ac_photoid_'+activeId).val(), "photo.photo_path" : $('#active_avatar').attr("src"), 
            "photo.photo_type_id" : 3, "photo.size_id" : 3, "photo.photo_name" : PhotoLocalName
        },
        dataType : "json",
        complete : function (data, textStatus)
        {
            if (eval("(" + data.responseText + ")").result == 0)
            {
                $('#active_subject').val("");
                $('#startime_str').val("");
                $('#endtime').html("");
                $('#active_content').val("");
                $("#active_time").val("0");
                $('#active_avatar').attr("src", "/images/Head.jpg");
				$("#ywc").hide();
				$('#uploadactive').show();
				$("#activeSub").attr("href", "javascript:subActive();");
				if($("#preactiveAvatar" + activeId).attr("src")!=null&&$("#preactiveAvatar" + activeId).attr("src")!=""&&$('#ac_photoid_'+activeId).val()==0){
				  delImg($("#preactiveAvatar" + activeId).attr("src"));
				 }
				 $("#startime_str").removeAttr("disabled");
				 $("#startime_hour").removeAttr("disabled");
				 $("#startime_min").removeAttr("disabled");
				 $("#active_time").removeAttr("disabled");
				 $('#startime_hour').val("00");
				$('#startime_min').val("00");
                alert("\u6210\u529F\u4FEE\u6539\u6D3B\u52A8");
            }
            else {
                alert("\u4FEE\u6539\u6D3B\u52A8\u5931\u8D25");
            }
        }
    });
}
function delActivePho(activeId)
{
   $("#ywc").hide();
   $('#uploadactive').show();
   $('#ac_photoid_'+activeId).val("0");
   $('#active_avatar').attr("src", "/images/Head.jpg");
}
function subdelActive(activeId,photoid)
{
    var bln = window.confirm("\u786E\u5B9A\u8981\u5220\u9664\u6D3B\u52A8\u4FE1\u606F\u5417?"); 
	if(bln){
		var request = $.ajax(
		{
			url : "/room!delActive.jspa", type : "post", data : 
			{
				"active.id" : activeId,"active.room_id" : $('#room_id').val(),
				"photo.id" : photoid
			},
			dataType : "json",
			complete : function (data, textStatus)
			{
				if (eval("(" + data.responseText + ")").result == 0)
				{   
				    if($("#preactiveAvatar" + activeId).attr("src")!=null&&$("#preactiveAvatar" + activeId).attr("src")!=""){
					   delImg($("#preactiveAvatar" + activeId).attr("src"));
					}
					
					$("#actice" + activeId).remove();
					
				}
				else {
					alert("\u7CFB\u7EDF\u9519\u8BEF\uFF0C\u5220\u9664\u6D3B\u52A8\u5931\u8D25\uFF01");
				}
			}
		});
	}
}
function subJoiner(activeID)
{
    var request = $.ajax(
    {
        url : "/room!addJoiner.jspa", type : "post", data : {
            "active.id" : activeID, "active.room_id" : $('#room_id').val()
        },
        dataType : "json",
        complete : function (data, textStatus)
        {
            if (eval("(" + data.responseText + ")").result == 0)
            {
                $("#joinAmount" + activeID).html(Number($("#joinAmount" + activeID).html()) + 1);
                //\u4FEE\u6539\u56FE\u7247\u663E\u793A
                $("#joinerStat" + activeID).attr("class", "activeCont0002");
                $("#preactiveA" + activeID).attr("href", "#");
                //\u5220\u9664cookie
                delCookie("joinerStat_" + activeID + "_" + $('#room_id').val() + "_" + $('#userid').val());
            }
            else if (eval("(" + data.responseText + ")").result ==- 1) {
                alert("\u7528\u6237\u672A\u767B\u5F55");
            }
            else {
                alert("\u7CFB\u7EDF\u9519\u8BEF");
            }
        }
    });
}
function subRoomInfo()
{
    if ($('#description').val().length > 100) {
        alert("\u4FE1\u606F\u8981\u6C42\u5728100\u5B57\u4EE5\u5185");
        return false;
    }
    var request = $.ajax(
    {
        url : "/room!editRoomInfo.jspa", type : "post", data : 
        {
            "room.description" : $('#description').val(), "room.create_time" : $('#create_time').val(), 
            "room.room_id" : $('#room_id').val(), "photo.photo_path" : checkphoto($('#preroomavatar').attr("src"), 
            $('#roomavatar').attr("src")), "photo.photo_type_id" : 1, "photo.size_id" : 1, "photo.photo_name" : PhotoLocalName
        },
        dataType : "json",
        complete : function (data, textStatus)
        {
            if (eval("(" + data.responseText + ")").result == 0)
            {   
			    if($('#create_time').val()==""){
			       $('#create_time').val("100");
			    }
                $('#preroomdes').html($('#description').val());
                $('#preroomavatar').attr("src", $('#roomavatar').attr("src"));
                alert("\u4FDD\u5B58\u6210\u529F");
            }
            else {
                alert("\u4FDD\u5B58\u5931\u8D25");
            }
        }
    });
}
function activeReIndex()
{
  if($('#active_avatar').attr('src').indexOf("?")>0){
     delImg($('#active_avatar').attr('src'));
  }
  window.location.reload();
  
}
function checkphoto(srPhoto, destPhoto)
{
    if (srPhoto == destPhoto) {
        return "";
    }
    else {
        return destPhoto;
    }
}
function getCookie(name)//\u53D6cookies\u51FD\u6570        

{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) {
        return unescape(arr[2]);
    }
    return null;
}
function delCookie(name)//\u5220\u9664cookie

{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) {
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
}
function delImg(srcImg)
{
    var index = srcImg.indexOf("?");
    if (index > 0) {
        srcImg = srcImg.substring(0, index);
    }
    var request = $.ajax(
    {
        url : "/room!delImg.jspa", type : "post", data : {
            imgsrc : srcImg
        },
        dataType : "json", complete : function (data, textStatus) { }
    });
}
var activetagstr="";
function activeTag(tagid)
{
   if (activetagstr==""){ 
    var request = $.ajax(
     {
        url : "/room!getActiveTag.jspa", type : "post", async:false,
        dataType : "json", complete : function (data, textStatus) {
		    activetagstr=data.responseText;
		}
      }
	 );
	}
	  var re=eval("(" + activetagstr + ")");
      if (!re.hasOwnProperty("result")){
		      if (tagid==-1){
			     for(var i=0;i<re.tags.length;i++){
				    $("#tag_category").append("<option value='"+re.tags[i].id+"'>"+re.tags[i].tagName+"</option>");
				 }
				}else{
				   for(var i=0;i<re.tags.length;i++){
				     if(tagid==0){
					    $("#tag_id option").remove();
					    $("#tag_id").append("<option value='0'>\u8BF7\u9009\u62E9</option>");
						return;
					 }
				     if (re.tags[i].id==tagid){
					    $("#tag_id option").remove();
					    var ctag=re.tags[i];
						for(var i=0;i<ctag.tags.length;i++){
				           $("#tag_id").append("<option value='"+ctag.tags[i].id+"'>"+ctag.tags[i].tagName+"</option>");
				        }
						break;
					 }
				 }
				}
		  }
    
}
function centerChange(){
  if($("#center_flag").attr("checked")=="checked"){
      $("#tag_category").removeAttr("disabled");
	  $("#tag_id").removeAttr("disabled");
  }else{
      $("#tag_category").attr("disabled","disabled");
	  $("#tag_id").attr("disabled","disabled");
  }
}
/*image auto resize*/
function AutoResizeImage(maxWidth, maxHeight, objImg) 
{
    var img = new Image();
    img.src = objImg.attr("src");
    img.onload = function ()
    {
        var hRatio;
        var wRatio;
        var Ratio = 1;
        var w = img.width;
        var h = img.height;
        wRatio = maxWidth  / w;
        hRatio = maxHeight  / h;
        if (maxWidth == 0 && maxHeight == 0) {
            Ratio = 1;
        }
        else 
        {
            if (maxWidth == 0) {
                //
                if (hRatio < 1) {
                    Ratio = hRatio;
                }
            }
            else 
            {
                if (maxHeight == 0) {
                    if (wRatio < 1) {
                        Ratio = wRatio;
                    }
                }
                else {
                    if (wRatio < 1 || hRatio < 1) {
                        Ratio = (wRatio <= hRatio ? wRatio : hRatio);
                    }
                }
            }
        }
        if (Ratio < 1) {
            w = w * Ratio;
            h = h * Ratio;
        }
        objImg.css("height", Math.round(h));
        objImg.css("width", Math.round(w));
        initCropActive(Ratio);
    }
}
var prox;
var proy;
var proxc;
var proyc;
function show(id)
{
    /*--\u6253\u5F00--*/
    clearInterval(prox);
    clearInterval(proy);
    clearInterval(proxc);
    clearInterval(proyc);
    var o = document.getElementById(id);
    o.style.display = "block";
    prox = setInterval(function ()
    {
        openx(o, 793)
    }, 10);
}
function openx(o, x)
{
    /*--\u6253\u5F00x--*/
    var cx = parseInt(o.style.width);
    if (cx < x) { }
    else {
        clearInterval(prox);
        proy = setInterval(function ()
        {
            openy(o, 276)
        }, 10);
    }
}
function openy(o, y)
{
    /*--\u6253\u5F00y--*/
    var cy = parseInt(o.style.height);
    if (cy < y) { }
    else {
        clearInterval(proy);
    }
}
function closeed(id)
{
    /*--\u5173\u95ED--*/
    clearInterval(prox);
    clearInterval(proy);
    clearInterval(proxc);
    clearInterval(proyc);
    var o = document.getElementById(id);
    if (o.style.display == "block") {
        proyc = setInterval(function ()
        {
            closey(o)
        }, 10);
    }
}
function closey(o)
{
    /*--\u6253\u5F00y--*/
    var cy = parseInt(o.style.height);
    if (cy > 0) {
        o.style.height = (cy - Math.ceil(cy / 5)) + "px";
    }
    else {
        clearInterval(proyc);
        proxc = setInterval(function ()
        {
            closex(o)
        }, 10);
    }
}
function closex(o)
{
    /*--\u6253\u5F00x--*/
    var cx = parseInt(o.style.width);
    if (cx > 0) {
        o.style.width = (cx - Math.ceil(cx / 5)) + "px";
    }
    else {
        clearInterval(proxc);
        o.style.display = "none";
    }
}

function getlengthStr(str){
     return str.replace(/[^\x00-\xff]/g,"**").length;
}
function checkMax(oTextArea,max){
       var length=getlengthStr(oTextArea.value);
       if( length> max){
                 oTextArea.value = oTextArea.value.substring(0,oTextArea.value.replace(/[^\x00-\xff]/g,"**").substring(0,max).replace(/\*\*/g,"1").length); 
                } 
}
 function isURL(str) {
       var strRegex = "^http://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$";
       var re = new RegExp(strRegex);
       if (re.test(str)) {
                return true;
            } else {
                 return false;
            }
}
